﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
using ListenMusic.Models.Reposistory.Public;
using ListenMusic.Models.Reposistory.Admin;
namespace ListenMusic.Controllers.Admin
{
    public class ManageSingerController : AdminController
    {        
        private int pagesize = 10;
        //
        // GET: /ManageSinger/
        //[Authorize(Roles="WesbiteAdmin")]
        public ActionResult ViewAllSinger(int? pageindex)
        {
            if (pageindex == null)
            {
                pageindex = 1;
            }            
            
            ViewBag.pageindex = pageindex;
            int count = _manageSinger.getAllSinger().Count();
            int totalSinger = 0;
            if (count % pagesize == 0)
            {
                totalSinger = (int)count / pagesize;
            }
            else
            {
                totalSinger = (int)Math.Ceiling((double)(count) / pagesize);
            }            
            ViewBag.totalSinger = totalSinger;
            ViewBag.allSinger = _manageSinger.getAllSinger().ToPagedList((pageindex ?? 1), pagesize).ToList();
            return View();
        }
        public JsonResult deleteSinger(int singerid)
        {
            bool rs = _manageSinger.deleteSinger(singerid);
            return Json(rs, JsonRequestBehavior.AllowGet);
        }
        public ActionResult InsertNewSingerPage()
        {
            CountryReposistory _country = new CountryReposistory();           
            ViewBag.country = _country.getAllCountry();
            return View();
        }
        public ActionResult ConfirmInsertNewSinger(string singername, HttpPostedFileBase filepicture, int country)
        {
            string pathPicture = Server.MapPath("~/Images/Singers/");
            AdminUploadReposistory admin = new AdminUploadReposistory();
            bool rs = admin.InsertNewSinger(filepicture, singername, country, pathPicture);
            if (rs)
            {
                return RedirectToAction("ViewAllSinger");
            }
            else
            {
                return RedirectToAction("InsertNewSingerPageer");
            }
        }
        public JsonResult ChangeDisplay(int singerid)
        {
            bool rs = _manageSinger.ChangeSinger(singerid);
            return Json(rs, JsonRequestBehavior.AllowGet);
        }
    }
}
